package Servlet;

import Service.AuditService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张
 * Date: 2025-03-15
 * Time: 13:18
 */
//处理用户改签
@WebServlet("/DisposeAuditServlet")
public class DisposeAuditServlet extends HttpServlet {
    private AuditService auditService = new AuditService();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf8");
        String auditId = req.getParameter("auditId");
        String ticketId = req.getParameter("ticketId");
        String newFlightId = req.getParameter("newFlightId");
        String type = req.getParameter("type");
        boolean ok = false;
        if(type.equals("pass")) {
            //通过申请
            ok = auditService.auditPass(auditId,ticketId,newFlightId);
        } else if(type.equals("refuse")) {
            //拒绝申请
            ok = auditService.auditRefuse(auditId,ticketId);
        }
        if(!ok) {
            req.setAttribute("status", "error");
            req.setAttribute("message", "操作失败");
            req.setAttribute("redirectUrl", "AuditsServlet?pageNo=1");
            req.setAttribute("waitSeconds", 2);
            req.getRequestDispatcher("skip.jsp").forward(req,resp);
        }
        req.getRequestDispatcher("AuditsServlet?pageNo=1").forward(req,resp);
    }


}
